package com.adui.mgt.performance.api;

import com.adui.mgt.performance.common.Result;
import com.adui.mgt.performance.entity.Course;
import com.adui.mgt.performance.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 课程crud
 **/
@RestController
@RequestMapping("/api/courses")
public class CourseApi {

    @Autowired
    private CourseService courseService;

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return Result.data(courseService.getById(id));
    }

    @GetMapping("/page")
    public Result findPage(@RequestBody Course course) {
        return courseService.findPage(course);
    }

    @PostMapping("/")
    public Result add(@RequestBody Course course) {
        courseService.getBaseMapper().insert(course);
        return Result.ok();
    }

    @PutMapping("/")
    public Result update(@RequestBody Course course) {
        courseService.getBaseMapper().updateById(course);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id) {
        courseService.removeById(id);
        return Result.ok();
    }
}
